<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function saveform()
	{
		if($("#sku").val()=="")
		{
			$("#skuerr").html('商品编号(SKU)不能为空！');
			return false;
		}
		if($("#name").val()=="")
		{
			$("#nameerr").html('不能为空！');
			return false;
		}
		if($("#costprice").val()=="" || $("#costprice").val()==0)
		{
			$("#costpriceerr").html('商品成本价不能为空或为0！');
			return false;
		}
		if($("#tbopertime").val()=="")
		{
			$("#tbopertimeerr").html('入库时间不能为空！');
			return false;
		}
		
		
		
		
		
		
		
		$("#otherForm").submit();
			
	}
function getsku()
{
	if($("#sku").val()){
$.post("/datareport/ajaxbutton", {"op": "getsku","sku":$("#sku").val(),"type":1},
		function(data){
			if(data==201)
			{
				$("#skuerr").html('商品编号(SKU)已经存在！');
			    $("#sku").val('');	
			}else{
				getmabangproduct();	
			}
		},"json");	
	}
}
function getmabangproduct()
{
		if($("#sku").val()){
	$.post("/datareport/ajaxbutton", {"op": "getmabangproduct","sku":$("#sku").val()},
		function(data){
			if(data==201)
			{
				$("#skuerr").html('商品编号(SKU)在马帮系统中不存在！');
			    $("#sku").val('');	
			}else{
				$("#name").val(data[0].NAME);
				$("#costprice").val(data[0].COSTPRICE);
				$("#tbopertime").val(data[0].tbopertime);
				
				
				
			}
		},"json");
		}
}
</script>
<title>添加新的商品</title>
<body class="withvernav">
<div class="bodywrapper">
 {{include file='/public/leftmenu.tpl'}}
    <div class="centercontent">
    
       <div class="pageheader notab">
            <h1 class="pagetitle">添加新的商品</h1>
            <span class="pagedesc"></span>
            <div class="menulist">
        		
               </div>
        </div><!--pageheader-->
        	
        <div id="contentwrapper" class="contentwrapper">
        	
        	<div id="basicform" class="subcontent">
					<form class="stdform stdform2"  id="otherForm" method="post" enctype='multipart/form-data' action="/datareport/saveproduct">
                    	
                    	 <p>
                         <input type="hidden" name="type" value="1" >
                        	<label>商品编号 *</label>
                            <span class="field">
                          <input type="text" name="sku" id="sku" class="width100" value="{{$detail.sku}}" onBlur="getsku()" required> 
                          <span id="skuerr"></span>
                            </span>
                        </p>
                         <p>
                        	<label>商品名称 *</label>
                            <span class="field">
                          <input type="text" name="name" id="name" class="width200" value="{{$detail.name}}" required>
                          <span id="nameerr"></span>
                            </span>
                        </p>
                          <p>
                        	<label>成本价 *</label>
                            <span class="field">
                          <input type="text" name="costprice" id="costprice" class="width100" value="{{$detail.costprice}}" required>
                          <span id="costpriceerr"></span>
                            </span>
                        </p>
                         <p>
                        	<label>正常卖价</label>
                            <span class="field">
                          <input type="text" name="price" id="price" class="width100" value="{{$detail.price}}" required>
                          <span id="priceerr"></span>
                            </span>
                        </p>
                          <p>
                        	<label>活动价</label>
                            <span class="field">
                          <input type="text" name="activityprice" id="activityprice" class="width100" value="{{$detail.activityprice}}">
                            <span id="activitypriceerr"></span>
                            </span>
                        </p>
                        
                         <p>
                        	<label>清仓价格</label>
                            <span class="field">
                          <input type="text" name="clearanceprice" id="clearanceprice" class="width100" value="{{$detail.clearanceprice}}">
                            </span>
                        </p>
                        <p>
                        	<label>采购连接</label>
                            <span class="field">
                          <input type="text" name="weburl" id="weburl" class="width400" value="{{$detail.weburl}}">
                            </span>
                        </p>
                        
                         <p>
                        	<label>入库时间</label>
                            <span class="field">
                       <input type="text"  name="tbopertime" id="tbopertime" value="{{$detail.tbopertime}} " onClick="WdatePicker({dateFmt:'yyyy-MM-dd '})" class="width100 hasDatepicker" />  <span id="tbopertimeerr"></span>
                            </span>
                        </p>
                        
                       
                      	<!-- <p>
                        	<label>图片地址</label>
                            <span class="field">
                             <span class="files"></span>
                            <span id="showimg"></span>
                          <input id="fileupload" type="file" name="mypic"><br><br>或图片链接<input type="text" class="width200" name="imgurl" id="imgurl" value="{{$detail.imgurl}}"></span>
                          </p>-->
                       
                        <p class="stdformbutton">
                        	<span ><button type="button" class="submit radius2" id="btn" onClick="saveform()" >保存商品</button>
                            <input type="hidden" name="id" value="{{$detail.id}}" id="id">
                        </p>
                    </form>
					
                    <br />

            </div><!--subcontent-->
            
            <!--subcontent-->
        
        </div><!--contentwrapper-->
        
	</div><!-- centercontent -->
    
    
</div><!--bodywrapper-->
<script type="text/javascript">
$(function () {
	var bar = $('.bar');
	var percent = $('.percent');
	var showimg = $('#showimg');
	var progress = $(".progress");
	var files = $(".files");
	var btn = $(".btn span");
	$("#fileupload").wrap("<form id='myform' action='/datareport/upfile' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
		$("#myform").ajaxSubmit({
			dataType:  'json',
			beforeSend: function() {
        		showimg.empty();
				progress.show();
        		var percentVal = '0%';
        		bar.width(percentVal);
        		percent.html(percentVal);
				btn.html("上传中...");
    		},
    		uploadProgress: function(event, position, total, percentComplete) {
        		var percentVal = percentComplete + '%';
        		bar.width(percentVal);
        		percent.html(percentVal);
    		},
			success: function(data) {
				files.html("<b>"+data.name+"("+data.size+"k)</b><br> <span class='delimg' rel='"+data.pic+"'>删除</span><br>");
				var img = "/uploads/"+data.pic;
				$("#imgurl").val(img);
				showimg.html("<img src='"+img+"'><br>");
				btn.html("添加附件");
			},
			error:function(xhr){
				btn.html("上传失败");
				bar.width('0')
				files.html(xhr.responseText);
			}
		});
	});
	
	$(".delimg").live('click',function(){
		var pic = $(this).attr("rel");
		$.post("/datareport/ajaxbutton?op=delimg",{imagename:pic},function(msg){
			if(msg==1){
				files.html("删除成功.");
				$("#imgurl").val('');
				showimg.empty();
				progress.hide();
			}else{
				alert(msg);
			}
		});
	});
});
</script>
</body>
</html>
